

//包名可能需要手动换
package productController

import (
	"encoding/json"
	"guli-shopping/api-service/protobuff/productProto"
	"github.com/gogf/gf/net/ghttp"
	"log"
)

type PmsCategoryBrandRelationController struct {
	Client productProto.PmsCategoryBrandRelationCheckerClient
}

func getPmsCategoryBrandRelationRequest() *productProto.PmsCategoryBrandRelationRequest {
	 return &productProto.PmsCategoryBrandRelationRequest{Query: &productProto.PmsCategoryBrandRelationQuery{}}
}

func (this* PmsCategoryBrandRelationController) FindAll(request *ghttp.Request)  {
	userRequest := getPmsCategoryBrandRelationRequest()

    page := request.GetInt32("page")
	size := request.GetInt32("size")
	model := &productProto.PmsCategoryBrandRelation{}
	request.Parse(model)
	userRequest.Query.Page=page
	userRequest.Query.Size=size
	userRequest.Query.Model=model

	all, err := this.Client.FindAll(request.Context(),userRequest)
	if err != nil {
		//记录日志
		log.Println(err)
	}
	request.Response.WriteJson(all)
}

func (this* PmsCategoryBrandRelationController) FindById(request *ghttp.Request)  {
	userRequest := getPmsCategoryBrandRelationRequest()
	id := request.GetInt64("id")
	userRequest.Id=id
	all, err := this.Client.FindById(request.Context(),userRequest)
	if err != nil {
		//记录日志
		log.Println(err)
	}
	request.Response.WriteJson(all)
}

func (this* PmsCategoryBrandRelationController) Delete(request *ghttp.Request)  {
	userRequest := getPmsCategoryBrandRelationRequest()
	ids :=request.GetString("ids")
	userRequest.Ids=ids
	all,err := this.Client.Delete(request.Context(),userRequest)
	if err != nil {
		//记录日志
		log.Println(err)
	}
	request.Response.WriteJson(all)
}

func (this* PmsCategoryBrandRelationController) Update(request *ghttp.Request)  {
	userRequest := getPmsCategoryBrandRelationRequest()
	user := productProto.PmsCategoryBrandRelation{}
	request.Parse(&user)
	userRequest.Model=&user
	all, err := this.Client.Update(request.Context(),userRequest)
	if err != nil {
		//记录日志
		log.Println(err)
	}
	request.Response.WriteJson(all)
}
func (this* PmsCategoryBrandRelationController) Save(request *ghttp.Request)  {
	userRequest := getPmsCategoryBrandRelationRequest()
	user := []*productProto.PmsCategoryBrandRelation{}
	list := request.GetStrings("list")
	for _, value := range list {
		temp := productProto.PmsCategoryBrandRelation{}
		json.Unmarshal([]byte(value),&temp)
		user=append(user,&temp)
	}
	userRequest.List=user
	all, err := this.Client.Save(request.Context(),userRequest)
	if err != nil {
		//记录日志
		log.Println(err)
	}
	//web端的不需要id,这是提供给service的
	all.Id=0
	request.Response.WriteJson(all)
}


func (this* PmsCategoryBrandRelationController) FindAllByBrandId(request *ghttp.Request)  {
	userRequest := getPmsCategoryBrandRelationRequest()
	id := request.GetInt64("brand_id")
	userRequest.Id=id
	all, err := this.Client.FindAllByBrandId(request.Context(),userRequest)
	if err != nil {
		//记录日志
		log.Println(err)
	}
	request.Response.WriteJson(all)
}
